package com.beeantec.jnrerc.modules.member.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beeantec.jnrerc.core.annon.LogInject;
import com.beeantec.jnrerc.core.api.ApiRest;
import com.beeantec.jnrerc.core.api.controller.BaseController;
import com.beeantec.jnrerc.dto.request.AdminLoginReqDTO;
import com.beeantec.jnrerc.entity.Job;
import com.beeantec.jnrerc.modules.member.service.JobService;
import com.beeantec.jnrerc.modules.user.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Anthony
 */
@Api(tags={"职位"})
@RestController
@RequestMapping("/api/job")
public class JobController extends BaseController {
    @Autowired
    private JobService jobService;



    /**
     * 获取职位详情
     * @return
     */
    @LogInject(title = "获取职位详情")
    @CrossOrigin
    @ApiOperation(value = "获取职位详情")
    @RequestMapping(value = "/detail", method = {RequestMethod.GET})
    public ApiRest<Job> login(@RequestParam("jobId") Integer jobId) {
        return success(jobService.getById(jobId));
    }


    /**
     * 获取职位详情
     * @return
     */
    @LogInject(title = "添加或编辑职位")
    @ApiOperation(value = "添加或编辑职位")
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public ApiRest<String> save(@RequestBody Job job) {
        if (jobService.saveOrUpdate(job)){
            return success("保存成功");
        }
        return failure("保存失败");
    }


    /**
     * 获取职位详情
     * @return
     */
    @LogInject(title = "删除职位")
    @ApiOperation(value = "删除职位")
    @RequestMapping(value = "/delete", method = {RequestMethod.GET})
    public ApiRest<String> delete(@RequestParam("jobId") Integer jobId) {
        if (jobService.removeById(jobId)){
            return success("删除职位成功");
        }
        return failure("删除职位失败");
    }

    /**
     * 获取职位详情
     * @return
     */
    @LogInject(title = "获取部门职位列表")
    @ApiOperation(value = "获取部门职位列表")
    @RequestMapping(value = "/list", method = {RequestMethod.GET})
    public ApiRest<List<Job>> list(@RequestParam("depId") String depId) {
        List<Job> list = new ArrayList<>();
        QueryWrapper<Job> jobQueryWrapper = new QueryWrapper<>();
        jobQueryWrapper.lambda().eq(Job::getDepId,Integer.parseInt(depId));
        list = jobService.list(jobQueryWrapper);
        return success(list);
    }
}